package com.cms.login;

import com.doman.OpenidData;
import com.resultmsg.BaseEnums;
import com.resultmsg.Result;
import com.resultmsg.Results;
import com.server.OpenidDataMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@CrossOrigin(origins = {"http://localhost:9528", "null"})
@RequestMapping(value = "/educloud")
@RestController
public class OpenidDataController {


    @Autowired
    private OpenidDataMapper openidDataMapper;


    @RequestMapping(value = "/openid/exist", method = RequestMethod.GET)
    public Result openidExist(@RequestParam String openid) {
        OpenidData res = openidDataMapper.selectByOpenid(openid);
        if (Objects.nonNull(res)) {
            return Results.successWithData(res, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
        } else {
            return Results.failureWithData("",BaseEnums.FORBIDDEN.code(), BaseEnums.FORBIDDEN.desc());
        }
    }
}
